CountrySelectWindow = function(){
	var data = [];
	var column = [
		 new Ext.grid.RowNumberer(),
		{
			dataIndex:'cname',
			header:'国家或地区',
			width:120
		}
	];
	var store = new Ext.data.JsonStore(
		{
			data:data,
			autoLoad:true,
			fields:['cid','cname']
		}
	);
	var countrystore = new Ext.data.JsonStore(
		{
			url:'findallorgstaffinfo.html',
			baseParams:{start:0,limit:12},
			totalProperty: 'totalCount', 
			root: 'data',
			fields:['cid','cname']
		}
	); 
	var search = function(){
		var form = north.getForm();
		var txtname = form.findField('searchname').getValue();
		var _obj = {start:0,limit:12,condition:txtname};
		var _url = ''+'/back/jsp/organise/findallorgstaffinfo.html';
		var _store=countrystore;
		_store.proxy.setUrl(_url,true);
		_store.baseParams = _obj;
		_store.load({params:_obj});
	};
	var histroyinfo =  function(){
		var form = north.getForm();
		var txtname = form.findField('searchname').getValue();
		var _obj = {start:0,limit:12,condition:txtname};
		var _url = ''+'/back/jsp/organise/findallorgstaffinfo.html';
		var _store=countrystore;
		_store.proxy.setUrl(_url,true);
		_store.baseParams = _obj;
		_store.load({params:_obj});
	}
	var north = new Ext.FormPanel(
		{
			height:38,
			region:"north",
			layout:"hbox",
			bodyStyle:"padding:6px 2px 2px 2px",
			layoutConfigs:{
				align:"middle"
			},
			keys:{
				key:Ext.EventObject.ENTER,
				scope:this,
				fn:search
			},
			defaultType:"label",
			defaults:{margins:"0 0 0 4"},
			items:[
				{xtype:"textfield",name:"searchname",width:260,maxLength:256},
				{xtype:"button",text:'查找',iconCls:"btn-search",scope:this,handler:search},
				{xtype:"button",text:'历史记录',iconCls:"btn-search",scope:this,handler:histroyinfo}
			]
		}
	);
	var selectedUserGrid = new Ext.grid.GridPanel(
		{
			id:'selectedUserGrid',
			title:'',
			store:store,
//			autoExpandColumn : 'userid',
			columns: column,
			height:400,
			width:200,
			region:'center'
		}
	);
	selectedUserGrid.on('rowdblclick',function(grid,index,e){
		var c=grid;
		var d=c.getSelectionModel().getSelections();
		var a=c.getStore();
		for(var b=0;b<d.length;b++) {
			c.stopEditing();
			a.remove(d[b]);
		}
	});
	var addAll = function () {
		var g=Ext.getCmp("contactGrid");
		var a=Ext.getCmp("selectedUserGrid");
		var h=a.getStore();
		var m=g.getSelectionModel().getSelections();
		for(var c=0;c<m.length;c++) {
			var d=m[c].data.cid;
			var k=m[c].data.cname;
			var f=false;
			for(var b=0;b<h.getCount();b++) {
				if(h.getAt(b).data.cid==d) {
					f=true;
					break;
				}
			}
			if(!f) {
				var l={
					cid:d,
					cname:k
				};
				var e=new h.recordType(l);
				a.stopEditing();
				h.add(e);
			}
		}
	};
	
	var removeAll=function () {
		var c=Ext.getCmp("selectedUserGrid");
		var d=c.getSelectionModel().getSelections();
		var a=c.getStore();
		for(var b=0;b<d.length;b++) {
			c.stopEditing();
			a.remove(d[b]);
		}
	};
	
	var tobarinfo = new Ext.Panel(
		{
			region:"west",
			frame:true,
			width:40,
			layout:{type:"vbox",pack:"center",align:"stretch"},
			defaultType:"button",
			items:[
				{
					iconCls:"rightarrow",
//					iconCls:"btn-right",
//					text:"添加",
					scope:this,
					handler:addAll
				},{
					iconCls:"leftarrow",
//					iconCls:"btn-left",
//					text:"去掉",
					scope:this,
					handler:removeAll
				}
			]
		}
	);
	var east=new Ext.Panel({
		layout:"border",
		region:"east",
		width:"200",
		height:"100%",
		border:false,
		autoScroll:true,
		items:[
			tobarinfo,
			selectedUserGrid
		]
	});
	
	
	
	
	var area = new Ext.tree.TreePanel(
		{
//			region:'west',
			title:'洲列表',
			root: new Ext.tree.AsyncTreeNode({
	        	uid:'dep-712',
	        	cpid:0,
	        	cid:0,
	        	iconCls:'depicon',
	        	text:'AAAAA',
	        	id:0
	        	
	        }),
	        loader:new Ext.tree.TreeLoader({
	        	 dataUrl: __ctxPath+'/back/countryinfo/findcoutryinfos.html',	
	        	 baseParams:{cpid:0,cnote:'1'},
	        	 listeners:{
	        	 	'beforeload':function(treeloader,node){
	        	 		this.baseParams.cpid = node.attributes.cid;
	        	 	}
	        	 }
	        }),
	        listeners:{
	        	'click': function(node){
	        		var cid = node.attributes.cid;
	        		var _obj = {start:0,limit:12,cpid:cid};
		    		var _url = __ctxPath+'/back/countryinfo/findcoutryinfosforgridbycpid.html';
		    		var _store=countrystore;
		    		_store.proxy.setUrl(_url,true);
		    		_store.baseParams = _obj;
					_store.load({params:_obj});
	            }
            },
            rootVisible:false, 
	        autoScroll:true
		}
	);
	area.getRootNode().expand();
	/*var path = '/dep-712/712/157';
	area.expandPath(path,'id',function(bSucess,oLastNode){  
		var selnode = area.getSelectionModel().select(oLastNode);  
		selnode.expandChildNodes();
	});*/
	
	
	var west = new Ext.Panel(
		{
			region:'west',
			layout:"accordion",
			width:200,
			split:true,
			header:false,
			collapsible:true,
			items:[area]
		}
	);
	var bbar = new Ext.PagingToolbar({
		store:countrystore,
		pageSize:20,
		displayInfo: true,   
		displayMsg:'{0},{1}'
     });
	var center = new Ext.grid.GridPanel(
		{
			region:'center',
			title:'国家列表',
			id:'contactGrid',
			store:countrystore,
			columns: column,
			height:400,
			width:400,
			bbar:bbar
		}
	)
	center.on("rowdblclick",function (grid,index,e) {
		var g=Ext.getCmp("contactGrid");
		var a=Ext.getCmp("selectedUserGrid");
		var h=a.getStore();
		var m=g.getSelectionModel().getSelections();
		for(var c=0;c<m.length;c++) {
			var d=m[c].data.cid;
			var k=m[c].data.cname;
			var f=false;
			for(var b=0;b<h.getCount();b++) {
				if(h.getAt(b).data.cid==d) {
					f=true;
					break;
				}
			}
			if(!f) {
				var l={
					cid:d,
					cname:k
				};
				var e=new h.recordType(l);
				a.stopEditing();
				h.add(e);
			}
		}
	});
	var confirm = function(){
		var countrys = [];
		var p = [];
		for (var i = 0; i < store.getCount(); i++) {
			var cm = store.getAt(i);
			countrys.push(cm.data);
			p.push(cm.get('cid'));
		}
		this.fireEvent('submit',this,countrys,p);
	}
	var cancel = function(){
		this.close();
	}
	var buttons = [
		{
			text:'确定',
			handler:confirm,
			scope:this
		},
		{
			text:'取消',
			handler:cancel,
			scope:this
		}
	];
	var config = {
		layout:'border',
		constrainHeader:true,
		constrain:true,
		modal : true,
		title: '选择出访国家或地区',
		iconCls:'copy',
        width: 650,
        height:400,
        minWidth: 300,
        minHeight: 200,
        plain:true,
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        buttons:buttons,
		items:[north,west,east,center]
	}
	CountrySelectWindow.superclass.constructor.call(this,config);
}
Ext.extend(CountrySelectWindow,Ext.Window);